﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spider.Data
{
    public class CommonDbHelper
    {
        private CommonDbDataProviderFactory factory=null;
        public CommonDbHelper()
        {
            factory = new CommonDbDataProviderFactory();
        }
        public CommonDbHelper(string conncetionSettingName)
        {
            factory = new CommonDbDataProviderFactory(conncetionSettingName);
        }
        public IDbConnection CreateDbConnection()
        {
            return factory.CreateConnection();
        }
        public IDbConnection CreateDbConnection(string connectionString)
        {
            return factory.CreateConnection(connectionString);
        }
        public IDbCommand CreateDbCommand()
        {
            return factory.CreateCommand();
        }
        public IDbCommand CreateDbCommand(string commandText,IDbConnection con)
        {
            IDbCommand cmd = CreateDbCommand(commandText);
            cmd.Connection = con;
            return cmd;
        }
        public IDbCommand CreateDbCommand(string commandText)
        {
            return factory.CreateCommand(commandText);
        }
        public IDbCommand CreateDbCommand(string commandText,CommandType commandType)
        {
            return factory.CreateCommand(commandText, commandType);
        }
        public IDbCommand CreateDbCommand(string commandText, CommandType commandType,IDbConnection con)
        {
            IDbCommand cmd = CreateDbCommand(commandText, commandType);
            cmd.Connection = con;
            return cmd;
        }
        public IDbDataAdapter CraeteDbDataAdapter()
        {
            return factory.CreateDataAdapter();
        }
        public IDbDataParameter CreateDbDataParameter()
        {
            return factory.CreateParameter();
        }
        public IDbDataParameter CreateInDbDataParameter(string parameterName)
        {
            IDbDataParameter parameter = CreateDbDataParameter();
            parameter.ParameterName = parameterName;
            parameter.Direction = ParameterDirection.Input;
            return parameter;
        }
        public IDbDataParameter CreateOutDbDataParameter(string parameterName)
        {
            IDbDataParameter parameter = CreateDbDataParameter();
            parameter.ParameterName = parameterName;
            parameter.Direction = ParameterDirection.Output;
            return parameter;
        }
        public IDbDataParameter CreateInOutDbDataParameter(string parameterName)
        {
            IDbDataParameter parameter = CreateDbDataParameter();
            parameter.ParameterName = parameterName;
            parameter.Direction = ParameterDirection.InputOutput;
            return parameter;
        }
        public IDbDataParameter CreateReturnDbDataParameter(string parameterName)
        {
            IDbDataParameter parameter = CreateDbDataParameter();
            parameter.ParameterName = parameterName;
            parameter.Direction = ParameterDirection.ReturnValue;
            return parameter;
        }
        public IDbDataParameter CreateInDbDataParameter(string parameterName,object value)
        {
            IDbDataParameter parameter = CreateInDbDataParameter(parameterName);
            parameter.Value = value==null?DBNull.Value:value;
            return parameter;
        }
        public IDbDataParameter CreateOutDbDataParameter(string parameterName, object value)
        {
            IDbDataParameter parameter = CreateOutDbDataParameter(parameterName);
            parameter.Value = value==null?DBNull.Value:value;
            return parameter;
        }
        public IDbDataParameter CreateInOutDbDataParameter(string parameterName, object value)
        {
            IDbDataParameter parameter = CreateInOutDbDataParameter(parameterName);
            parameter.Value = value==null?DBNull.Value:value;
            return parameter;
        }
        public IDbDataParameter CreateReturnDbDataParameter(string parameterName, object value)
        {
            IDbDataParameter parameter = CreateReturnDbDataParameter(parameterName);
            parameter.Value = value==null?DBNull.Value:value;
            return parameter;
        }
        public IDbDataParameter CreateInDbDataParameter(string parameterName, object value,DbType dbType)
        {
            IDbDataParameter parameter = CreateInDbDataParameter(parameterName,value);
            parameter.DbType = dbType;
            return parameter;
        }
        public IDbDataParameter CreateInOutDbDataParameter(string parameterName, object value, DbType dbType)
        {
            IDbDataParameter parameter = CreateInOutDbDataParameter(parameterName, value);
            parameter.DbType = dbType;
            return parameter;
        }
        public IDbDataParameter CreateOutDbDataParameter(string parameterName, object value, DbType dbType)
        {
            IDbDataParameter parameter = CreateOutDbDataParameter(parameterName, value);
            parameter.DbType = dbType;
            return parameter;
        }
        public IDbDataParameter CreateReturnDbDataParameter(string parameterName, object value, DbType dbType)
        {
            IDbDataParameter parameter = CreateInDbDataParameter(parameterName, value);
            parameter.DbType = dbType;
            return parameter;
        }
        public IDbDataParameter CreateInDbDataParameter(string parameterName, object value, DbType dbType,int size)
        {
            IDbDataParameter parameter = CreateInDbDataParameter(parameterName, value,dbType);
            parameter.Size = size;
            return parameter;
        }
        public IDbDataParameter CreateOutDbDataParameter(string parameterName, object value, DbType dbType, int size)
        {
            IDbDataParameter parameter = CreateOutDbDataParameter(parameterName, value, dbType);
            parameter.Size = size;
            return parameter;
        }
        public IDbDataParameter CreateInOutDbDataParameter(string parameterName, object value, DbType dbType, int size)
        {
            IDbDataParameter parameter = CreateInOutDbDataParameter(parameterName, value, dbType);
            parameter.Size = size;
            return parameter;
        }
        public IDbDataParameter CreateReturnDbDataParameter(string parameterName, object value, DbType dbType, int size)
        {
            IDbDataParameter parameter = CreateReturnDbDataParameter(parameterName, value, dbType);
            parameter.Size = size;
            return parameter;
        }
        public IDbDataParameter CreateInDbDataParameter(string parameterName, object value, DbType dbType, int size, byte scale)
        {
            IDbDataParameter parameter = CreateInDbDataParameter(parameterName, value, dbType,size);
            parameter.Scale = scale;
            return parameter;
        }
        public IDbDataParameter CreateOutDbDataParameter(string parameterName, object value, DbType dbType, int size, byte scale)
        {
            IDbDataParameter parameter = CreateOutDbDataParameter(parameterName, value, dbType, size);
            parameter.Scale = scale;
            return parameter;
        }
        public IDbDataParameter CreateInOutDbDataParameter(string parameterName, object value, DbType dbType, int size, byte scale)
        {
            IDbDataParameter parameter = CreateInOutDbDataParameter(parameterName, value, dbType, size);
            parameter.Scale = scale;
            return parameter;
        }
        public IDbDataParameter CreateReturnDbDataParameter(string parameterName, object value, DbType dbType, int size, byte scale)
        {
            IDbDataParameter parameter = CreateReturnDbDataParameter(parameterName, value, dbType, size);
            parameter.Scale = scale;
            return parameter;
        }
    }
}
